package com.bolt.report.definition;

import com.bolt.report.engine.fill.FillField;
import com.bolt.report.engine.model.Expression;

import java.io.Serializable;

public class FieldDefinition implements Serializable {

    private String name;

    private SortOrder sortOrder;

    private String expr;

    public FieldDefinition() {

    }

    public FieldDefinition(String name, SortOrder sortOrder, String expr) {
        this.name = name;
        this.sortOrder = sortOrder;
        this.expr = expr;
    }

    public FieldDefinition(String name, Integer sortCode, String expr) {
        this(name, SortOrder.toType(sortCode), expr);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public SortOrder getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(SortOrder sortOrder) {
        this.sortOrder = sortOrder;
    }

    public String getExpr() {
        return expr;
    }

    public void setExpr(String expr) {
        this.expr = expr;
    }

    public FillField getFillFiled() {
        FillField fillField = new FillField();
        fillField.setName(getName());
        fillField.setValueClass(getClass());
        fillField.setExpression(new Expression(getExpr()));
        return fillField;
    }
}